package com.moyu.common.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.moyu.common.core.constants.Constants;
import com.moyu.common.core.utils.ThreadLocalUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * Mybatis公共数据初始化
 *
 * @Author 赵彦博
 * @Date 2024/12/21 16:43
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        // ThreadLocalUtils.get(Constants.USER_ID, Long.class)
        this.strictInsertFill(metaObject, "createBy", Long.class, 1l);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "update_time", LocalDateTime.class, LocalDateTime.now());
        // ThreadLocalUtils.get(Constants.USER_ID, Long.class)
        this.strictUpdateFill(metaObject, "update_by", Long.class, 1l);
    }
}
